import ua from './ua'
import api from 'api'

export default {
  ready: (callback) => {
    if (ua.wx) {
      let jsApiList = ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ", "onMenuShareWeibo", "onMenuShareQZone"]
      api.wxConfig().then(res => {
        if (res.code === 0 && res.data) {
          let cfg = res.data
          wx.config({
            debug: false,
            appId: 'wxb01ccdde86f4613e',
            timestamp: cfg.timestamp,
            nonceStr: cfg.nonceStr,
            signature: cfg.signature,
            jsApiList: jsApiList
          })
          wx.ready(function () {
            callback && callback(jsApiList)
          })
          wx.error(function (res) {
            console.log(res)
          })
        }
      })
    }
  }
}
